package org.tbjd.client.mediators;



import org.tbjd.client.exceptions.NoUpperDecisionmakerFoundException;
import org.tbjd.client.exceptions.NoUpperMediatorFoundException;
import org.tbjd.client.exceptions.TBJDException;
import org.tbjd.client.interfaces.HasMediator;
import org.tbjd.client.interfaces.Observer;

public class TaskListMediator extends AbstractMediator implements Observer, HasMediator {

	private AbstractMediator mediator = null;

	public void decide(Object action) {
		System.out.println("TaskListMediator.decide()");

		try {
			delegate(action);
		} catch (NoUpperDecisionmakerFoundException e) {
			e.printStackTrace();
		} catch (NoUpperMediatorFoundException e) {
			e.printStackTrace();
		}
	}

	public void delegate(Object action) throws NoUpperDecisionmakerFoundException, NoUpperMediatorFoundException {
		System.out.println("TaskListMediator.delegate()");

		try {
			this.mediator.decide(action);
		} catch (TBJDException e) {
			e.printStackTrace();
		}
	}

	public void handle(Object action) {

	}

	public void update(Object sender) {
		System.out.println("TaskListMediator.update()");
		notifyObservers(sender);
	}

	public void setMediator(AbstractMediator mediator) {
		this.mediator = mediator;
		this.mediator.addObserver(this);
	}


}
